package com.example.basemodel.base

import android.app.Activity
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import com.coorchice.library.SuperTextView
import com.example.basemodel.R
import com.example.basemodel.databinding.ActivityBaseHeadBinding
import com.example.basemodel.utils.StatusBarUtils

/**
 * Administrator
 * 2021/8/9
 * desc：
 */
open class DefaultHeadStyle : BaseStyle, View.OnClickListener {
    lateinit var mBinding: ActivityBaseHeadBinding
    lateinit var mActivity: Activity
    override fun initHedView(activity: Activity, view: View): View {
        this.mActivity = activity
        mBinding = ActivityBaseHeadBinding.inflate(activity.layoutInflater)
        StatusBarUtils.setBackMarginTop(activity, mBinding.baseHeadBackBtn, false)
        mBinding.baseHeadcontent.addView(view)
        mBinding.baseHeadBackBtn.setOnClickListener(this)
        return mBinding.root
    }

    override fun initHedView(activity: Activity): View {
        this.mActivity = activity
        mBinding = ActivityBaseHeadBinding.inflate(activity.layoutInflater)
        StatusBarUtils.setBackMarginTop(activity, mBinding.baseHeadBackBtn, false)
        mBinding.baseHeadBackBtn.setOnClickListener(this)
        return mBinding.root
    }

    override fun addContentView(view: View) {
        mBinding.baseHeadcontent.addView(view)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.baseHeadBackBtn -> {
                mActivity.finish()
            }
        }
    }

    /**
     * 设置标题
     *
     */
    fun setHeadTitle(text: String) {
        mBinding.baseHeadTitleTv.text = text
    }

    fun setTitleColor(text: String, @ColorInt color: Int) {
        mBinding.baseHeadTitleTv.text = text
        mBinding.baseHeadTitleTv.setTextColor(color)
    }

    fun setTitleBackgroundColor(@ColorInt color: Int) {
        mBinding.baseHeadBg.setBackgroundColor(color)
    }

    fun setTitleBackgroundResource(@DrawableRes resid: Int) {
        mBinding.baseHeadBg.setBackgroundResource(resid)
    }

    fun setLeftImageResource(@DrawableRes resid: Int) {
        mBinding.baseHeadBackBtn.setImageResource(resid)
    }

    fun setRightImageResource(resid: Int) {
        mBinding.baseHeadRightBtn.setImageResource(resid)
    }

    fun getRightTextView(): SuperTextView {
        return mBinding.baseHeadRightTextTv
    }

    fun setRightImageClick(onClick: View.OnClickListener) {
        mBinding.baseHeadRightBtn.setOnClickListener(onClick)
    }

    fun setRightTitleClick(onClick: View.OnClickListener) {
        mBinding.baseHeadRightTextTv.setOnClickListener(onClick)
    }

    fun setRightTextColor(text: String, @ColorInt color: Int) {
        mBinding.baseHeadRightTextTv.text = text
        mBinding.baseHeadRightTextTv.setTextColor(color)
    }

    /**
     * 设置右边文字
     */
    fun setRightTitle(text: String) {
        mBinding.baseHeadRightTextTv.text = text
    }
}